package com.tolls;

//单例懒汉设计模式
public class Singleton {

    //该类的所有对象共享一个实例
    private static  Singleton instance;

    //饿汉模式
    // private static Singleton instance = new Singleton();

    //私有化构造方法，该类无法被实例化
    private Singleton(){}

    public  static synchronized  Singleton getInstance(){

        if(instance == null){
            System.out.println("懒汉模式");
            instance = new Singleton();
        }

        return  instance;
    }

    public void showMessage(){

        System.out.println("Hello World!");
    }

    public static void main(String[] args) {


        getInstance();
    }

}
